package com.HuangJiaQing.www.controller;

import com.HuangJiaQing.www.model.Orders;
import com.HuangJiaQing.www.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author HONOR
 * @date 2022/7/29 15:12
 */
@Controller
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @RequestMapping(value = "/addOrders/{id}",method = RequestMethod.POST)
    @ResponseBody
    public String addOrders(@PathVariable("id")Integer id,String method){
        Boolean b = ordersService.insertOrders(id, method);
        String s = b.toString();
        return s;
    }

    @RequestMapping(value = "/selectOrders", method = RequestMethod.GET)
    public String selectOrders(Model model){
        List<Orders> orders = ordersService.selectOrders(model);
        model.addAttribute("orders",orders);
        return "orders";
    }

    @RequestMapping(value = "/toCollect",method = RequestMethod.GET)
    public String toCollect(Model model){
        List<Orders> orders = ordersService.selectOrdersNeedCollect();
        model.addAttribute("orders",orders);
        return "collect";
    }

    @RequestMapping(value = "/updateOrders/{id}",method = RequestMethod.PUT)
    public String updateOrdersIsCollect(@PathVariable("id") Integer id){
        ordersService.updateOrdersIsCollect(id);
        return "redirect:/toCollect";
    }
}
